<template>
  <a-drawer
    :title="title"
    :width="720"
    :dialog-style="{ top: '20px' }"
    :visible="visible"
    @close="close"
  >
    <!-- 查询区域-start -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="refreshTable">
        <a-row :gutter="24">
          <a-col :md="12" :sm="8">
            <a-form-item label="日期">
              <a-range-picker v-model="queryParam.crtDtRange" />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="refreshTable" icon="search">查询</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-end -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="add" type="primary" icon="plus">创建售后记录</a-button>
    </div>

    <div>
      <s-table
        ref="table"
        rowKey="id"
        :columns="columns"
        :data="loadData"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="process(record)">处理</a>
          <a-divider type="vertical"/>
          <a @click="edit(record)">修改</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => del(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
    </div>

    <after-sale-modal ref="modal" @ok="refreshTable"></after-sale-modal>
  </a-drawer>
</template>

<script>
import { ListMixin } from '@/mixins/ListMixin'
import { apiQueryAfterSaleList } from '@/api/order'
import AfterSaleModal from './AfterSaleModal'

const columns = [
  {
    title: '问题描述',
    dataIndex: 'problemDesc',
    key: 'problemDesc'
  },
  {
    title: '状态',
    dataIndex: 'statusDesc',
    key: 'statusDesc'
  },
  {
    title: '处理结果',
    dataIndex: 'result',
    key: 'result'
  },
  {
    title: '日期',
    dataIndex: 'crtDt',
    key: 'crtDt'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    width: 200
  }
]

export default {
  name: 'AfterSaleList',
  mixins: [ListMixin],
  components: {
    AfterSaleModal
  },
  data () {
    return {
      orderId: '',
      visible: false,
      title: '',
      columns,
      loadData: parameter => {
        return apiQueryAfterSaleList(Object.assign(parameter, this.queryParam)).then(res => {
          return res
        })
      }
    }
  },
  methods: {
    show (title, record) {
      this.title = title
      this.visible = true
      if (record) {
        this.orderId = record.id
        this.queryParam.orderId = record.id
        this.$nextTick(() => {
          this.refreshTable()
        })
      }
      this.orderId = record.id
    },
    close () {
      this.visible = false
    },
    add () {
      this.$refs.modal.show('新增售后记录', { orderId: this.orderId })
    },
    process (record) {
      this.$refs.modal.show('处理售后记录', record)
    },
    edit (record) {
      this.$refs.modal.show('修改售后记录', record)
    }
  }
}
</script>

<style scoped>

</style>
